/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package PACKAGE_NAME
 * @Description:
 * @Date 2025/5/21 17:10
 */

public class StringTest {

    public static void main(String[] args) {
        //字符串：不可变的序列，底层用char[]数组存储
      /*  String str = "Hello";
        //存储单个字符 用char类型
        char c = 'H';
        //存储多个字符 用char[]数组
        char[] chars = {'H', 'e', 'l', 'l', 'o'};
        //存储多个字符 用String类型
        String str1 = "Hello";*/

        //String的创建
        //方式一：直接赋值

/*        //方式二：new String()
        String str1 = new String("Hello");
        //方式三：char[]数组
        char[] chars = {'H', 'e', 'l', 'l', 'o'};
        String str2 = new String(chars);
        System.out.println(str2);
        //方式四：String的拼接 concat()
        String str3 = "Hello" + "World";
        System.out.println(str3);
        //方式五：截取字符串

        String s = new String(chars, 2, 2);
        System.out.println(s);*/
        //方式六：String的常用方法
         String str = "h中bc123db123e**fbds121…b…";
         String str1 = "rwerewsfsdh中bcwrqw1dbe**fb…b…";
        //String的常用方法
        //1.获取字符串的长度
        /*int length = str.length();
        System.out.println(length);
        //2.获取字符串的某个字符
        char c = str.charAt(0);
        System.out.println(c);
        //3.获取字符串的某个字符的ASCII码
        int i = str.codePointAt(1);
        System.out.println(i);
        //4.获取字符串的某个字符的Unicode码
        int i1 = str.codePointBefore(1);
        System.out.println(i1);
        //5.获取字符串某一个字符第一次出现的位置
        int i2 = str.indexOf("bcd");
        System.out.println("b2:"+i2);
        //6.是否包含字符串
        boolean b = str.contains("bc");
        System.out.println(b);
        //7.是否以某个字符串开头
        boolean b1 = str.startsWith("h2");
        System.out.println(b1);
        //8.是否以某个字符串结尾
        boolean b2 = str.endsWith("b…");
        System.out.println(b2);*/

        //9.字符串替换
        String replace = str.replace("b", "B");
        System.out.println(replace);
        String g = str.replaceFirst("\\d+", "G");
        System.out.println(g);

        String s = str.replaceAll("\\d+", "A");
        System.out.println(s);


    }
}